export class Message {
    
    type: string;
    //发送者
    sender: any | null;
    //接收者
    receiver: any | null;
    data: any;

    constructor(type: TYPE|string) {
        this.type = type;
    }
    static send(sender:string,type:string,data:any):Message{
        const msg = new Message(type);
        msg.sender = sender;
        msg.data = data;
        return msg;
    }
    static message(sender: any, receiver: any, data: any): Message {
        const msg = new Message(TYPE.msg);
        msg.receiver = receiver;
        msg.sender = sender;
        msg.data = data;
        return msg;
    }
    static join(sender:any):Message{
        const msg = new Message(TYPE.join)
        msg.sender=sender;
        return msg;
    }
    static offer(sender: string, desc: any): Message {
        const msg = new Message(TYPE.offer)
        msg.sender=sender;
        msg.data=desc;
        return msg;
    }
    static answer(sender: string, desc: any): Message {
        const msg = new Message(TYPE.answer)
        msg.sender=sender;
        msg.data=desc;
        return msg;
    }
    static leave(sender:any):Message{
        const msg = new Message(TYPE.leave)
        msg.sender=sender;
        return msg;
    }
}
export enum TYPE {
    msg = "msg",
    join = "join",
    leave ="leave",
    offer ="offer",
    answer = "answer",
}